package com.lik.javadeep.stack;

import java.util.Stack;

/**
 * 进制转换
 */
public class Convert {
    public static void main(String[] args) {

        Stack<Integer> stack = convert(12, 2);

        String result = "";
        while (!stack.empty()) {
            result += stack.pop().toString();
        }

        System.out.println(result);
    }

    /**
     * @param num  目标数字
     * @param base 进制
     * @return
     */
    private static Stack<Integer> convert(int num, int base) {
        Stack<Integer> stack = new Stack<>();

        while (num > 0) {
            // 余数压栈
            stack.push(num % base);

            num /= base;
        }

        return stack;
    }
}
